// 学员模块的所有vuex相关
import { getStudentApi } from '../../api/student'
const studentStore = {
  state: {
    studentList: [],//学员列表数据
    pageStart: 1,//当前页码
    pageSize: 3,//一页多少条数据
    total: 0,//数据总条数
    endPage: 0,//尾页
  },
  namespaced: true,
  mutations: {
    changeData (state, res) {
      if (res.err) {
        state.studentList = []
      } else {
        state.studentList = res.data.list;//赋值学员列表数据
        state.pageSize = res.data.pageSize;//当前一个的条数
        state.total = res.data.count; //总数据条数
        state.endPage = Math.ceil(res.data.count / res.data.pageSize) //尾页
      }
    },
    changePage (state, page) { //改变当前页码的mutations
      state.pageStart = page;
    }
  },
  actions: {
    async getStudentAction ({ commit }, data) { //获取学员列表的actions
      var res = await getStudentApi(data)
      console.log(res)
      commit("changeData", res)
      return Promise.resolve(true)
    }
  },
  getters: {
    studentList: state => state.studentList,//学员列表数据
    pageStart: state => state.pageStart,//当前页码
    pageSize: state => state.pageSize,//一页多少条数据
    total: state => state.total,//数据总条数
    endPage: state => state.endPage//尾页
  },
}
export default studentStore